<?php
	/*
	 * AJAX call to save an edited or new SMS message in the "inbox" table of the database.
	 *
	 * Variables:
	 *   id (int) : Record ID of the SMS message, 0 if new SMS
	 *   txt (string) : The body of the SMS message
	 *
	 * Returns: string: error or SMS message
	 *
	 */

	if($_POST["id"] > 0){
		$sql = mysql_query("UPDATE inbox SET TextDecoded=\"".mysql_real_escape_string(stripslashes($_POST["txt"]))."\" WHERE ID=".round($_POST["id"])." LIMIT 1");
	}else{
		$sql = mysql_query("INSERT INTO inbox SET TextDecoded=\"".mysql_real_escape_string(stripslashes($_POST["txt"]))."\", ReceivingDateTime=NOW(), UpdatedInDB=NOW()");
	}
	if(mysql_error() != ""){
		echo "Error updating database...";
		echo '<br />';
		echo mysql_error();
	}else{
		echo mysql_real_escape_string(stripslashes($_POST["txt"]));
	}
	exit;
?>